﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HRM.BLL;
using HRM.DAL.DAO;
using HRM.DAL.Report;
using HRM.ReportManager;

namespace HRM.ReportAll
{
    public partial class rptEmployeeUI1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadProject();
                Loadcatagory();

            }
        }
        private void Loadcatagory()
        {
            List<Catagory> catagories = new List<Catagory>();
            CatagoryManager manager = new CatagoryManager();
            catagories = manager.GetAllCatagories();
            ddempCatagory.DataTextField = "EmpCatagory";
            ddempCatagory.DataValueField = "Id";
            ddempCatagory.DataSource = catagories;
            ddempCatagory.DataBind();
            ddempCatagory.Items.Insert(0, "---Choose Any---");

        }
        private void LoadProject()
        {
            List<Project> projects = new List<Project>();
            ProjectManager manager = new ProjectManager();
            projects = manager.GetAllProjects();
            ddlEmpProject.DataTextField = "ProjectName";
            ddlEmpProject.DataValueField = "Id";
            ddlEmpProject.DataSource = projects;
            ddlEmpProject.DataBind();
            ddlEmpProject.Items.Insert(0, "---Choose Any---");

        }

        protected void SearchByProject(object sender, EventArgs e)
        {

            Company company = new Company();
            company = company.GetCompanyInfo();

            RptEmployeeManager manager = new RptEmployeeManager();
            List<EmployeeReport> employee = new List<EmployeeReport>();
            int projectId = Convert.ToInt32(ddlEmpProject.Value);
            employee = manager.SearchEmployeeByProject(projectId);
            int i = 0;
            foreach (EmployeeReport employeeReport in employee)
            {
                employee[i].Company = company.Name;
                employee[i].Address = company.Address;
                i++;
            }
            EmployeeReportByProject empReport = new EmployeeReportByProject();
            empReport.SetDataSource(employee);
            CrystalReportViewer1.ReportSource = empReport;
            //  empReport.PrintToPrinter(1,false,0,0);
        }

        protected void SearchByCatagory(object o, EventArgs e)
        {
            Company company = new Company();
            company = company.GetCompanyInfo();

            RptEmployeeManager manager = new RptEmployeeManager();
            List<EmployeeReport> employees = new List<EmployeeReport>();
            Catagory catagory = new Catagory();
            catagory.Id = Convert.ToInt32(ddempCatagory.Value);
            employees = manager.SearchEmployeeByCatagory(catagory);
            int i = 0;
            foreach (EmployeeReport employeeReport in employees)
            {
                employees[i].Company = company.Name;
                employees[i].Address = company.Address;
                i++;
            }
            EmployeeReportByCatagory report = new EmployeeReportByCatagory();
            report.SetDataSource(employees);
            CrystalReportViewer1.ReportSource = report;

        }
        protected void SearchByStatus(object o, EventArgs e)
        {
            Company company = new Company();
            company = company.GetCompanyInfo();

            RptEmployeeManager manager = new RptEmployeeManager();
            List<EmployeeReport> employees = new List<EmployeeReport>();
            Status aStatus = new Status();
            employees = manager.SearchEmployeeByStatus(ddStatus.Value);
            int i = 0;
            foreach (EmployeeReport employeeReport in employees)
            {
                employees[i].Company = company.Name;
                employees[i].Address = company.Address;
                i++;
            }

            EmployeeReportByStatus report = new EmployeeReportByStatus();
            report.SetDataSource(employees);
            CrystalReportViewer1.ReportSource = report;

        }
    }
}